package nl.rainbowsheep.reisorg.rest.service.controller;

import nl.rainbowsheep.reisorg.rest.service.controller.exception.ForbiddenException;
import nl.rainbowsheep.reisorg.rest.service.controller.exception.PageNotFoundException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 *  With controlleradvice we can only handle exceptions that occur wihtin a controller. 
 *  Some exceptions happen outside of that range. I.E. 404 because no controller exists.
 *  We redirect these kind of requests to this controller.
 * 
 */
@RestController
@RequestMapping("/error")
public class ErrorController {
    
    @RequestMapping(value = "/404", method = RequestMethod.GET)
    public void throwNotFoundException() {
        throw new PageNotFoundException();
    }
    
    @RequestMapping(value= "/401", method = RequestMethod.GET)
    public void throwForbiddenException() throws Exception {
        throw new ForbiddenException();
    }
}
